import dayjs from 'dayjs';

/**
 * 获取日期范围选择器时间戳，开始时间00:00:00 结束时间：23:59:59
 * @param {Array} value [Date, Date]
 */
/* eslint-disable camelcase */
export const getDateRangeTimestamp = value => {
  const [_start_time, _end_time] = value;
  if (!(_start_time && _end_time)) return [null, null];

  const startTime = dayjs(_start_time).unix();
  // const endTime = dayjs(`${dayjs(_end_time).format('YYYY-MM-DD')} 23:59:59`).unix();
  const endTime =
    dayjs(_end_time)
      .add(1, 'day')
      .unix() - 1;
  return [startTime, endTime];
};

export const getDateRangeDate = value => {
  const [_start_time, _end_time] = value;
  if (!(_start_time && _end_time)) return [null, null];
  const startTime = _start_time;
  const endTime = _end_time;
  return [startTime, endTime];
};

/**
 * 获取时间戳
 * @param {Array} value Date
 */
export const getDateTimestamp = value => {
  if (!dayjs(value).isValid()) return null;
  return dayjs(value).unix();
};

/**
 * 获取时间年月日
 * @param {Array} value Date
 * @return []
 */
export const getDateYMD = value => {
  if (!dayjs(value).isValid()) return [null, null, null];
  const date = dayjs(value);
  return [date.get('year'), date.get('month') + 1, date.get('date')];
};
